#include <stdio.h>
#include <stdlib.h>

#define NUMBER	500000

#define FORZ(i, max)	for(i = 0; i < max; i++)
#define FOR1(i, max)	for(i = 1; i <= max; i++)

typedef struct _pair {
	int v2;
	int v3;
} Pair;

int absi(int a) {
	return a < 0 ? -a : a;
}

int getDist(int a, int b, int n) {
	int ret = absi(a - b);
	if(ret > n/2) {
		ret = (n - ret) * -1;
	}
	if(a > b) ret *= -1;
	return ret;
}

int getIndex(int a, int d, int n) {
	int ret = a + d;
	if(ret < 0) {
		return n + ret - 1;
	} else if(ret > n) {
		return ret - n;
	}
}

void reverse(int *in, int *out, int n) {
	int i;
	FORZ(i, n) {
		out[in[i]] = i;
	}
}

void shTab(int * tab, int n) {
	int i;
	FORZ(i, n) {
		printf("%d ", tab[i]);
	}
	printf("\n");
}

void shPairs(Pair * pairs, int n) {
	int i;
	FORZ(i, n) {
		printf("(%d,%d) ", pairs[i].v2, pairs[i].v3);
	}
	printf("\n");
}

int pairCmp(const void * aa, const void * ab ) {
	Pair *a, *b;
	a = (Pair*)aa;
	b = (Pair*)ab;
	if(a->v2 > b->v2)
		return 1;
	else if(a->v2 < b->v2)
		return -1;
	else {
		if(a->v3 > b->v3)
			return 1;
		else if(a->v3 < b->v3)
			return -1;
	}
	return 0;
}

int main() {
	int i, j, n, *b1, *b2, *b3, *r2, *r3, r, maxr;
	Pair *pairs, *pair;
/*
	printf("%d\n", getDist(0, 6, 7));
	printf("%d\n", getIndex(5, 3, 7));

	return 0;
*/	
	//----------------------------------------
	scanf("%d", &n);
	
	b1 = malloc(n * sizeof(int));
	b2 = malloc(n * sizeof(int));
	b3 = malloc(n * sizeof(int));

	r2 = malloc((n + 1) * sizeof(int));
	r3 = malloc((n + 1) * sizeof(int));
	
	pairs = malloc(n * sizeof(Pair));
	
	FORZ(i, n) {
		scanf("%d", &b1[i]);
	}
	FORZ(i, n) {
		scanf("%d", &b2[i]);
	}
	FORZ(i, n) {
		scanf("%d", &b3[i]);
	}
	//----------------------------------------
	reverse(b2, r2, n);
	reverse(b3, r3, n);
	
	/*
	shTab(b1, n);
	shTab(b2, n);
	shTab(b3, n);
	shTab(r2, n + 1);
	shTab(r3, n + 1);
	*/
	
	//------ getting pairs -------------------
	FORZ(i, n) {
		pairs[i].v2 = getDist(i, r2[b1[i]], n);
		pairs[i].v3 = getDist(i, r3[b1[i]], n);
	}
	
	//shPairs(pairs, n);
	qsort(pairs, n, sizeof(Pair), pairCmp);
	//shPairs(pairs, n);
	
	pair = &pairs[0];
	maxr = 0;
	r = 0;
	FORZ(i, n) {
		if(pairCmp(pair, &pairs[i]) != 0) {
			r = 1;
			pair = pairs + i;
			//printf("maxr=%d\n", maxr);
		} else {
			r++;
		}
		if(maxr < r)
			maxr = r;
	}

	printf("%d\n", maxr);
			
	return 0;
}
